/**
 * 首页
 * @author yaohuan
 * @date 2019/03/19
 */
define(['plugins/echarts/echarts.min'], function (echarts) {

    var self,
        app = win.app;


    var Admin = app.Module.extend({
        init: function () {
            self = this;
            self._super({}, win);

        },
        //初始化数据
        initData: function () {
            var myChart = echarts.init(document.getElementById('chart'));
            var names = [];
            names[0] = '潜在客户';
            names[1] = '意向客户';
            names[2] = '立项客户';
            names[3] = '商务客户';
            names[4] = '成交客户';
            app.ajax({
                xurl: "crm/gwat160/getCount",
                cb: function (result) {
                    if (result.ok) {
                        var datas = [];
                        datas[4] = result.data.data.count1;
                        datas[3] = result.data.data.count2;
                        datas[2] = result.data.data.count3;
                        datas[1] = result.data.data.count4;
                        datas[0] = result.data.data.count5;
                        document.getElementById('td1').innerHTML = names[0] + ' ' + datas[4] + '家';
                        document.getElementById('td2').innerHTML = names[1] + ' ' + datas[3] + '家';
                        document.getElementById('td3').innerHTML = names[2] + ' ' + datas[2] + '家';
                        document.getElementById('td4').innerHTML = names[3] + ' ' + datas[1] + '家';
                        document.getElementById('td5').innerHTML = names[4] + ' ' + datas[0] + '家';
                        var option = {
                            title: {
                                text: '销售漏斗(Sales Funnel)'
                            },
                            legend: {
                                x: 10,
                                y: 25,
                                data: names
                            },
                            calculable: true,
                            series: [
                                {
                                    name: '销售漏斗(Sales Funnel)',
                                    type: 'funnel',
                                    left: '10px',
                                    top: 60,
                                    bottom: 60,
                                    width: '80%',
                                    minSize: '0%',
                                    maxSize: '100%',
                                    sort: 'none',
                                    gap: 2,
                                    label: {
                                        show: false,
                                        position: 'inside'
                                    },
                                    data: [
                                        {value: 100,name:names[0]},
                                        {value: 80,name:names[1]},
                                        {value: 60,name:names[2]},
                                        {value: 40,name:names[3]},
                                        {value: 20,name:names[4]}
                                    ]
                                }
                            ]
                        };
                        myChart.setOption(option);
                    }
                }
            });

        },
        _ready: function () {
            new Vue({
                el: '#admin',
                data: {},
                methods: {}
            });
            self.initData();
        },
        _lazy: function () {
            this._super();
        }
    });

    return new Admin();

});